/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.biz.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.biz.entity.BizOrderdetail;
import com.thinkgem.jeesite.modules.biz.service.BizOrderdetailService;

/**
 * 订单Controller
 * @author tiancheng
 * @version 2018-09-17
 */
@Controller
@RequestMapping(value = "${adminPath}/biz/bizOrderdetail")
public class BizOrderdetailController extends BaseController {

	@Autowired
	private BizOrderdetailService bizOrderdetailService;
	
	@ModelAttribute
	public BizOrderdetail get(@RequestParam(required=false) String id) {
		BizOrderdetail entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bizOrderdetailService.get(id);
		}
		if (entity == null){
			entity = new BizOrderdetail();
		}
		return entity;
	}
	
	@RequiresPermissions("biz:bizOrderdetail:view")
	@RequestMapping(value = {"list", ""})
	public String list(BizOrderdetail bizOrderdetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BizOrderdetail> page = bizOrderdetailService.findPage(new Page<BizOrderdetail>(request, response), bizOrderdetail); 
		model.addAttribute("page", page);
		return "modules/biz/bizOrderdetailList";
	}

	@RequiresPermissions("biz:bizOrderdetail:view")
	@RequestMapping(value = "form")
	public String form(BizOrderdetail bizOrderdetail, Model model) {
		model.addAttribute("bizOrderdetail", bizOrderdetail);
		return "modules/biz/bizOrderdetailForm";
	}

	@RequiresPermissions("biz:bizOrderdetail:edit")
	@RequestMapping(value = "save")
	public String save(BizOrderdetail bizOrderdetail, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bizOrderdetail)){
			return form(bizOrderdetail, model);
		}
		bizOrderdetailService.save(bizOrderdetail);
		addMessage(redirectAttributes, "保存订单成功");
		return "redirect:"+Global.getAdminPath()+"/biz/bizOrderdetail/?repage";
	}
	
	@RequiresPermissions("biz:bizOrderdetail:edit")
	@RequestMapping(value = "delete")
	public String delete(BizOrderdetail bizOrderdetail, RedirectAttributes redirectAttributes) {
		bizOrderdetailService.delete(bizOrderdetail);
		addMessage(redirectAttributes, "删除订单成功");
		return "redirect:"+Global.getAdminPath()+"/biz/bizOrderdetail/?repage";
	}

}